<template>
	<view>
		<image src="@/static/code.png" class="content">
		</image>
		<view class="contenta">
			<view class="card">
				<image src="@/static/codback.png" class="codeback" />
				<!-- <p class='title' style="font-weight: bold;">{{name}}</p> -->
				<p class='title' style="font-weight: bold;">重庆中心城区医疗废物收运平台</p>
				<image :src="imgBase64" class="imgarr">
					<p class="mark">点击保存图片下载二维码</p>
			</view>
			<view class="sub" @click="dowload()">
				保存图片
			</view>
		</view>

	</view>
</template>

<script>
	import { getOrgzDetail } from '@/utils/api.js'
	export default {
		data() {
			return {
				imgBase64: '',
				name: ''
			}
		},
		mounted() {
			let detail = JSON.parse(uni.getStorageSync('detail'))
			this.imgBase64 = detail.qrCode
			this.getOrgzDetail()
		},
		methods: {
			getOrgzDetail(){
				getOrgzDetail().then(res=>{
					console.log('机构:', res)
					this.name = res.data.institutionName
				})
			},
			dowload() {
				// uni.saveImageToPhotosAlbum({
				// 	filePath: this.imgBase64,
				// 	success: function() {
				// 		uni.showToast({
				// 			title: '图片保存成功'
				// 		});
				// 	},
				// 	fail: function(err) {
				// 		uni.showToast({
				// 			title: '图片保存失败',
				// 			icon: 'none'
				// 		});
				// 		console.log('saveImageToPhotosAlbum fail', err);
				// 	}
				// });
				let saveImg=this.imgBase64.replace(/^data:image\/\w+;base64,/, "");//去掉data:image/png;base64,
				var timestamp = Date.now()
				uni.getFileSystemManager().writeFile({
				    filePath: wx.env.USER_DATA_PATH + '/' + timestamp + '.png',
					data: saveImg,
					encoding: 'base64',
					success: res2 => {
						uni.saveImageToPhotosAlbum({
							filePath: wx.env.USER_DATA_PATH + '/' + timestamp + '.png',
							success: function() {
								uni.showToast({
									title:'保存成功',
									duration: 2000,
									mask: false,
									icon: 'success'
								})
							},
				      fail: function() {}
						})
					},
				    fail: err2 => {
				        console.log(err2)
				    }
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		height: calc(100vh - 88rpx);
		background-size: 100% 100%;
		box-sizing: border-box;

	}

	.contenta {
		position: absolute;
		top: 120rpx;
		left: 50%;
		transform: translate(-50%);
	}

	.codeback {
		width: 160rpx;
		height: 160rpx;
		position: absolute;
		left: 50%;
		top: 0%;
		transform: translate(-50%, -50%);

	}

	.card {
		position: relative;
		width: 610rpx;
		height: 714rpx;
		background: #ffffff;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 110rpx 0 0;
		text-align: center;

		p {
			font-size: 36rpx;
			font-family: PingFang SC, PingFang SC-Semibold;
			font-weight: Semibold;
			text-align: left;
			color: #333333;
			text-align: center;

		}

		.imgarr {
			width: 400rpx;
			height: 400rpx;
			margin: auto;
		}

		.mark {
			font-size: 26rpx;
			font-family: PingFang SC, PingFang SC-Regular;
			font-weight: Regular;
			text-align: center;
			color: #666666;
			position: relative;
			top: 0rpx;
		}

	}

	.sub {
		width: 610rpx;
		height: 110rpx;
		background: #3db020;
		border-radius: 20rpx;
		text-align: center;
		line-height: 110rpx;
		font-size: 30rpx;
		font-family: PingFang SC, PingFang SC-Regular;
		font-weight: Regular;
		text-align: center;
		color: #ffffff;
		margin-top: 60rpx;

	}
</style>